//
//  ICShareSuccessView.m
//  ICome
//
//  Created by ENN on 16/9/1.
//  Copyright © 2016年 iCom. All rights reserved.
//

#import "ICShareSuccessView.h"
#import "ICHeaderFile.h"

@interface ICShareSuccessView ()

@property (nonatomic, weak) UIButton *titBtn;
@property (nonatomic, weak) UIButton *cancelBtn;
@property (nonatomic, weak) UIButton *confirmBtn;
@property (nonatomic, weak) UIView *lineView2;
@property (nonatomic, weak) UIView *lineView3;

@end

@implementation ICShareSuccessView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 5.0;
    }
    return self;
}


- (void)setDisplayName:(NSString *)displayName
{
    _displayName = displayName;
    [self.cancelBtn setTitle:[NSString stringWithFormat:@"返回%@",displayName] forState:UIControlStateNormal];
    [self.confirmBtn setTitle:@"留在iCom" forState:UIControlStateNormal];
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    self.titBtn.frame = CGRectMake(0, 12, 150, 60);
    _titBtn.centerX = self.width*0.5;
    self.lineView2.frame = CGRectMake(0, 85, self.width, 0.5);
    CGFloat height = self.height - self.lineView2.bottom;
    self.cancelBtn.frame = CGRectMake(0,self.lineView2.bottom, self.width*0.5-1, height);
    self.lineView3.frame = CGRectMake(self.cancelBtn.right, self.lineView2.bottom, 0.5, height);
    self.confirmBtn.frame = CGRectMake(self.lineView3.right, self.cancelBtn.top, self.width-self.cancelBtn.width-self.lineView3.width, height);
}

- (void)backOtherApp
{
    [[NSNotificationCenter defaultCenter] postNotificationName:ICShareBackOtherAppNotification object:nil];
}

- (void)stayInApp
{
    [[NSNotificationCenter defaultCenter] postNotificationName:ICShareStayInAppNotification object:nil];
}


#pragma mark - Getter

- (UIButton *)titBtn
{
    if (!_titBtn) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn.titleLabel setFont:[UIFont systemFontOfSize:20.0]];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamedFromiComeSDKBundle:@"icon_share_successed"] forState:UIControlStateNormal];
        [btn setTitle:@"分享成功" forState:UIControlStateNormal];
        [btn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 10)];
        [self addSubview:btn];
        _titBtn = btn;
    }
    return _titBtn;
}


- (UIButton *)cancelBtn
{
    if (!_cancelBtn) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
         [btn.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
         [btn addTarget:self action:@selector(backOtherApp) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
        _cancelBtn = btn;
    }
    return _cancelBtn;
}

- (UIButton *)confirmBtn
{
    if (!_confirmBtn) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
        [btn addTarget:self action:@selector(stayInApp) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
        _confirmBtn = btn;
    }
    return _confirmBtn;
}

- (UIView *)lineView2
{
    if (!_lineView2) {
        UIView *line = [[UIView alloc] init];
        line.backgroundColor = ICRGB(0xc4c4c4);
        [self addSubview:line];
        _lineView2 = line;
    }
    return _lineView2;
}

- (UIView *)lineView3
{
    if (!_lineView3) {
        UIView *line = [[UIView alloc] init];
        line.backgroundColor = ICRGB(0xc4c4c4);
        [self addSubview:line];
        _lineView3 = line;
    }
    return _lineView3;
}

@end
